-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Added Borůvka's algorithm. #4645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
graphs/boruvka.py
Outdated
|
||
class Graph: | ||
"""Class Graph.""" | ||
def __init__(self, num_of_nodes): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: __init__
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: num_of_nodes
graphs/boruvka.py
Outdated
self.m_edges = [] | ||
self.m_component = {} | ||
|
||
def add_edge(self, u, v, weight): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: add_edge
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: u
Please provide descriptive name for the parameter: u
Please provide type hint for the parameter: v
Please provide descriptive name for the parameter: v
Please provide type hint for the parameter: weight
graphs/boruvka.py
Outdated
|
||
self.m_edges.append([u, v, weight]) | ||
|
||
def find_component(self, u): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: find_component
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: u
Please provide descriptive name for the parameter: u
graphs/boruvka.py
Outdated
return u | ||
return self.find_component(self.m_component[u]) | ||
|
||
def set_component(self, u): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: set_component
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: u
Please provide descriptive name for the parameter: u
graphs/boruvka.py
Outdated
for k in self.m_component.keys(): | ||
self.m_component[k] = self.find_component(k) | ||
|
||
def union(self, component_size, u, v): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: union
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: component_size
Please provide type hint for the parameter: u
Please provide descriptive name for the parameter: u
Please provide type hint for the parameter: v
Please provide descriptive name for the parameter: v
graphs/boruvka.py
Outdated
|
||
print(self.m_component) | ||
|
||
def boruvka(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: boruvka
. If the function does not return a value, please provide the type hint as: def function() -> None:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
graphs/boruvka.py
Outdated
class Graph: | ||
"""Class Graph.""" | ||
|
||
def __init__(self, num_of_nodes) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide type hint for the parameter: num_of_nodes
graphs/boruvka.py
Outdated
self.m_edges = [] | ||
self.m_component = {} | ||
|
||
def add_edge(self, u, v, weight) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide type hint for the parameter: u
Please provide descriptive name for the parameter: u
Please provide type hint for the parameter: v
Please provide descriptive name for the parameter: v
Please provide type hint for the parameter: weight
graphs/boruvka.py
Outdated
|
||
self.m_edges.append([u, v, weight]) | ||
|
||
def find_component(self, u) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide type hint for the parameter: u
Please provide descriptive name for the parameter: u
graphs/boruvka.py
Outdated
return u | ||
return self.find_component(self.m_component[u]) | ||
|
||
def set_component(self, u) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide type hint for the parameter: u
Please provide descriptive name for the parameter: u
graphs/boruvka.py
Outdated
for k in self.m_component.keys(): | ||
self.m_component[k] = self.find_component(k) | ||
|
||
def union(self, component_size, u, v) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide type hint for the parameter: component_size
Please provide type hint for the parameter: u
Please provide descriptive name for the parameter: u
Please provide type hint for the parameter: v
Please provide descriptive name for the parameter: v
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added Borůvka's algorithm, a graph algorithm that finds the minimum spanning tree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
graphs/boruvka.py
Outdated
self.m_edges = [] | ||
self.m_component = {} | ||
|
||
def add_edge(self, u: int, v: int, weight: int) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide descriptive name for the parameter: u
Please provide descriptive name for the parameter: v
graphs/boruvka.py
Outdated
|
||
self.m_edges.append([u, v, weight]) | ||
|
||
def find_component(self, u: int) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide descriptive name for the parameter: u
graphs/boruvka.py
Outdated
return u | ||
return self.find_component(self.m_component[u]) | ||
|
||
def set_component(self, u: int) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide descriptive name for the parameter: u
graphs/boruvka.py
Outdated
for k in self.m_component.keys(): | ||
self.m_component[k] = self.find_component(k) | ||
|
||
def union(self, component_size: list, u: int, v: int) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide descriptive name for the parameter: u
Please provide descriptive name for the parameter: v
Added Borůvka's algorithm, a graph algorithm that finds the minimum spanning tree. |
This a Borůvka's algorithm, a simple greedy algorithm to find the Minimum spanning tree of a grap. It is also the oldest know graph algorithm, works as efficient as Kruskal's and Prim's algorithm. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the tests :)
…panning tree. Solved Test Cases Errors.
Hi, I have Fixed the Tests. Can you please review the code. Thank you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Final Changes for Test Case Errors.
…panning tree. Solved Test Cases Errors.
…panning tree. Solved Test Cases Errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test Case Errors Solved.
Hi, Can you please Review my Code. |
Please reformat with black because of precommit build |
…panning tree. Solved Test Cases Errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Final
Not really :) |
Even Spaces are not acceptable, is it? 😔 |
Rules are Strict. 😂 |
…panning tree. Solved Test Cases Errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Precommiting seems difficult than writing Algorithm. Now Final Review Please.
@l3str4nge
…panning tree. Solved Test Cases Errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reduced Each Line Length, Code Formatting.
@l3str4nge
…panning tree. Solved Test Cases Errors.Removed WhiteSpaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed WhiteSpaces.
Final Review Please. |
graphs/boruvka.py
Outdated
|
||
|
||
class Graph: | ||
"""Class Graph.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary comment.
graphs/boruvka.py
Outdated
def set_component(self, u_node: int) -> None: | ||
"""Finds the component index of a given node""" | ||
|
||
if self.m_component[u_node] == u_node: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be just self.m_component[u_node] != u_node:
and then we don't need else
graphs/boruvka.py
Outdated
component_size[u_node] += component_size[v_node] | ||
self.set_component(v_node) | ||
|
||
print(self.m_component) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this print statement
graphs/boruvka.py
Outdated
num_of_components = self.m_v | ||
|
||
while num_of_components > 1: | ||
for i in range(len(self.m_edges)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling len()
each iteration is inefficient.
…panning tree. Code Changes.
…panning tree. Code Changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requested code changes done. Please review my code.
@l3str4nge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 🚀
Can I write python code from scratch for Singular Vector Decompositions and Principal Component Analysis? Thank you So Much. |
* Added Borůvka's algorithm. * Added Borůvka's algorithm, a graph algorithm that finds the minimum spanning tree. * Added Borůvka's algorithm, a graph algorithm that finds the minimum spanning tree. * Added Borůvka's algorithm, a graph algorithm that finds the minimum spanning tree. * Added Borůvka's algorithm, a graph algorithm that finds the minimum spanning tree. * Added Borůvka's algorithm, a graph algorithm that finds the minimum spanning tree. Solved Test Cases Errors. * Added Borůvka's algorithm, a graph algorithm that finds the minimum spanning tree. Solved Test Cases Errors. * Added Borůvka's algorithm, a graph algorithm that finds the minimum spanning tree. Solved Test Cases Errors. * Added Borůvka's algorithm, a graph algorithm that finds the minimum spanning tree. Solved Test Cases Errors. * Added Borůvka's algorithm, a graph algorithm that finds the minimum spanning tree. Solved Test Cases Errors. * Added Borůvka's algorithm, a graph algorithm that finds the minimum spanning tree. Solved Test Cases Errors. * Added Borůvka's algorithm, a graph algorithm that finds the minimum spanning tree. Solved Test Cases Errors.Removed WhiteSpaces. * Added Borůvka's algorithm, a graph algorithm that finds the minimum spanning tree. Code Changes. * Added Borůvka's algorithm, a graph algorithm that finds the minimum spanning tree. Code Changes.
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}
.